﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>SQL查询表-外部数据源</title>
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/easyUI/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script src="../../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../../Comm/Gener.js" type="text/javascript"></script>
    <base target="_self" />
    <style type="text/css">
        .style1
        {
            width: 184px;
        }
    </style>
    <script type="text/javascript" language="javascript">

        var CONST_STRUCTS = [{ No: '0', Name: '普通的编码表(具有No,Name)' }, { No: '1', Name: '树结构(具有No,Name,ParentNo)'}];

        /**
         * 数据格式切换
         */
        function loadStructSet(value, text) {
            if (value == CONST_STRUCTS[0].No) {
                $("#rootTr").hide();
            } else {
                $("#rootTr").show();
                // 根节点值
                $("#TB_RootValue").val("0");
            }
        }

        //页面启动函数.
        $(function () {

          //绑定数据源.
            GenerBindEntities("DDL_FK_DBSrc", "BP.Sys.SFDBSrcs", "local");

            var mytb = document.getElementById("TB_Name");
            mytb.focus();
            $('#TB_Name').blur(function () //文本失去焦点时触发的事件
            {
                var TB_Name = document.getElementById("TB_Name").value;
                var val = $('input:radio[name="RB_QPJP"]:checked').val();
                if (TB_Name == "") {
                    document.getElementById("TB_No").value = "";
                    return;
                }

                if (val == "ziduanquanpin") {
                    ParseStringToPinYin(TB_Name, true);
                }
                else {
                    ParseStringToPinYin(TB_Name, false);
                }

            });
            //点击全拼
            $('input[id=RB_QP]').change(function () {
                var TB_Name = document.getElementById("TB_Name").value;
                ParseStringToPinYin(TB_Name, true, "SQL");
            });
            //点击简拼
            $('input[id=RB_JP]').change(function () {
                var TB_Name = document.getElementById("TB_Name").value;
                ParseStringToPinYin(TB_Name, false,"SQL");
            });

        });
 
        // 保存
        function Save() {

            var no = $("#TB_No").val() || "";
            var name = $("#TB_Name").val() || "";
            if (no == "" || name == "") {
                alert('请输入编号名称.');
                return;
            }

            if ($("#DDL_CodeStruct").val() == CONST_STRUCTS[1].No) {

                var rootValue = $("#TB_RootValue").val() || "";
                if (rootValue == "") {
                    alert("根节点值必须填写！");
                    return;
                }
            }

            if (!$("#TB_SelectStatement").val() || $("#TB_SelectStatement").val().length == 0) {
                alert("SQL语句必须填写！");
                $("#TB_SelectStatement").focus();
                return;
            }

            var en = new Entity("BP.Sys.SFTable");
            en.CopyForm();

            if (en.IsExits() == true) {
                alert("编号已经存在[" + en.No + "]请使用其他的编号.");
                return;
            }

            en.SrcType = 3; //自定义数据表.
            en.FK_Val = en.No;
            en.Insert();

            alert("保存成功.");
            window.location.href = "Default.htm";

        }
    </script>
</head>
<body>
    <form action="" id="cc">
        <table style="width: 95%; margin: 5px; padding: 5px;">
            <caption>
                <a href="./Default.htm">返回</a> - SQL查询表-外部数据源
            </caption>
            <tr>
                <th>项目</th>
                <th class="style1">值</th>
                <th>备注</th>
            </tr>

             <tr>
                <td >字典名称</td>
                <td class="style1"><input type="text" id="TB_Name" name="TB_Name" /></td>
                <td>创建字典表的中文名称</td>
            </tr>

            <tr>
                <td >字典编号</td>
                <td class="style1"><input type="text" id="TB_No" name="TB_No" /></td>
                <td> <input type="radio" name="RB_QPJP" id="RB_QP" checked="checked"  value="ziduanquanpin" /> <label for="RB_QP">全拼</label>   
   <input type="radio" name="RB_QPJP" id="RB_JP"  value="ziduanjianpin" />  <label for="RB_JP">简拼</label>   </td>
            </tr>
           
            <tr>
                <td >数据源</td>
                <td class="style1"><select id="DDL_FK_DBSrc" name="DDL_FK_DBSrc" /></td>
                <td>选择字典表所属数据源</td>
            </tr>
            <tr>
                <td >数据格式</td>
                <td class="style1">
                    <select id="DDL_CodeStruct" name="DDL_CodeStruct" onchange="loadStructSet(this.value, this.options[this.selectedIndex].text)">
                    
                    <option value="0" selected=true> 普通的编码表(具有No,Name) </option>
                    <option value="1"> 树结构(具有No,Name,ParentNo)</option>


                    </select>
                </td>
                <td>选择具体有指定字段的格式</td>
            </tr>
            <tr id="rootTr" style="display: none;">
                <td >根节点值</td>
                <td class="style1"><input type="text" id="TB_RootValue" name="TB_RootValue" /></td>
                <td>填写此树的根节点值,也可是一个表达式 比如:WebUser.FK_Dept </td>
            </tr>
            <tr>
                <td >SQL语句</td>
                <td class="style1" colspan="2">
                    
                    <textarea type="text" id="TB_SelectStatement" name="TB_SelectStatement" style="width: 98%;" >
                    </textarea>

                    <br />
                    支持cc表达式比如:SELECT No,Name FROM Port_Emp WHERE FK_Dept='@WebUser.FK_Dept'
                </td>
            </tr>

            <tr>
                <td colspan="3">
                <input type=button value="Save" onclick="Save()" />
                  <!--  <a href="javascript:void(0)" id="Btn_Save" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="Save()">保存</a>-->
                </td>
            </tr>
        </table>

        
<font color=gray>
<fieldset>
<legend>帮助</legend>
<ul>
<li>SQL语句必须包含指定结构指定的列.</li>
<li>SQL语句支持ccbpm表达式</li>
<li>例如1: SELECT No,Name FROM Port_Emp WEHRE FK_Dept='@WebUser.FK_Dept' </li>
<li>例如2: SELECT No,Name,ParnetNo FROM Port_Dept WEHRE ParentNo='@WebUser.FK_Dept' </li>
</ul>
</fieldset>
</font>

    </form>
</body>
</html>
